Skip to content

fix: Graph now notify updater when cycles are formed or broken#1647

Merged
triceo merged 3 commits into
TimefoldAI:mainfrom
Christopher-Chianelli:fix/1641
Jun 13, 2025
Merged

fix: Graph now notify updater when cycles are formed or broken#1647
triceo merged 3 commits into
TimefoldAI:mainfrom
Christopher-Chianelli:fix/1641

Conversation

@Christopher-Chianelli

Copy link
Copy Markdown
Contributor

Previously, the updater only considered nodes that were changed from an edge insertion or deletion. However, an edge insertion/deletion can also change the looped status of a disconnected node. For example, if we have a -> b and b -> a, and we
remove a -> b, only b is marked as changed. This is incorrect, since a changed indirectly, since it is no longer looped. Thus, the graph implementations now mark any nodes whose SCC change from singleton to multinode (looped) and vice-versa.

Previously, the updater only considered nodes that were changed from
an edge insertion or deletion. However, an edge insertion/deletion
can also change the looped status of a disconnected node.
For example, if we have a -> b and b -> a, and we
remove a -> b, only b is marked as changed. This is incorrect, since
a changed indirectly, since it is no longer looped. Thus, the
graph implementations now mark any nodes whose SCC change from
singleton to multinode (looped) and vice-versa.
@triceo triceo requested a review from Copilot June 12, 2025 17:52
@triceo triceo added this to the v1.24.0 milestone Jun 12, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the graph implementation to notify the updater when nodes’ looped (cycle) status changes by propagating a shared BitSet through graph operations and recording SCC status flips.

  • Method signatures for commitChanges, addEdge, and removeEdge now accept a BitSet changed to mark nodes whose cycle membership toggles.
  • Tests in VariableListenerSupportTest are updated to pass the new changed parameter; a new DefaultTopologicalGraphTest is added.
  • DefaultTopologicalOrderGraph tracks and flags nodes whose SCC size moves between singleton and multi-node loops, and adds a toString for debugging.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
VariableListenerSupportTest.java Updated overridden addEdge/removeEdge to include BitSet changed.
DefaultTopologicalGraphTest.java New test class for DefaultTopologicalOrderGraph.
TopologicalOrderGraph.java Changed signatures of commitChanges, addEdge, removeEdge to take BitSet changed.
DefaultVariableReferenceGraph.java Pass the shared changed BitSet into graph operations and commit.
DefaultTopologicalOrderGraph.java Added isNodeInLoopedComponent, track SCC status flips, and debug toString().
Comments suppressed due to low confidence (2)

core/src/main/java/ai/timefold/solver/core/impl/domain/variable/declarative/TopologicalOrderGraph.java:13

  • The new changed parameter isn’t documented in the Javadoc. Please add an @param changed explaining that it is a BitSet used to collect nodes whose looped status has changed.
void commitChanges(BitSet changed);

core/src/test/java/ai/timefold/solver/core/impl/domain/variable/declarative/DefaultTopologicalGraphTest.java:5

  • [nitpick] The test class name omits "Order" and doesn’t match the tested DefaultTopologicalOrderGraph. Consider renaming this to DefaultTopologicalOrderGraphTest for consistency.
public class DefaultTopologicalGraphTest extends AbstractTopologicalGraphTest<DefaultTopologicalOrderGraph> {

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
53.8% Coverage on New Code (required ≥ 70%)

See analysis details on SonarQube Cloud

@triceo triceo merged commit d253438 into TimefoldAI:main Jun 13, 2025
39 of 43 checks passed
@Christopher-Chianelli Christopher-Chianelli deleted the fix/1641 branch May 14, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Declarative Shadow Variable throws an UndoMove corruption exception

3 participants